<template>
  <div class="monitor-header">
    <div class="header-left">
      <h2 class="page-title">
        <i class="el-icon-monitor"></i>
        数据监控
      </h2>
      <div class="status-indicator">
        <span class="status-dot" :class="connectionStatus"></span>
        <span class="status-text">{{ connectionStatusText }}</span>
      </div>
    </div>
    <div class="header-right">
      <el-button-group>
        <el-button
          :type="autoRefresh ? 'primary' : 'default'"
          size="small"
          @click="handleToggleAutoRefresh">
          <i class="el-icon-refresh"></i>
          {{ autoRefresh ? '停止刷新' : '自动刷新' }}
        </el-button>
        <el-button size="small" @click="handleExport">
          <i class="el-icon-download"></i>
          导出数据
        </el-button>
        <el-button size="small" @click="handleOpenSettings">
          <i class="el-icon-setting"></i>
          设置
        </el-button>
      </el-button-group>
    </div>
  </div>
</template>

<script>
export default {
  name: "MonitorHeader",
  props: {
    connectionStatus: {
      type: String,
      default: 'online',
      validator: value => ['online', 'warning', 'offline'].includes(value)
    },
    connectionStatusText: {
      type: String,
      default: '连接正常'
    },
    autoRefresh: {
      type: Boolean,
      default: true
    },
    lastUpdateTime: {
      type: String,
      default: ''
    }
  },
  methods: {
    handleToggleAutoRefresh() {
      this.$emit('toggle-auto-refresh');
    },
    handleExport() {
      this.$emit('export-data');
    },
    handleOpenSettings() {
      this.$emit('open-settings');
    }
  }
};
</script>

<style lang="scss" scoped>
.monitor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding: 16px 20px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);

  .header-left {
    display: flex;
    align-items: center;
    gap: 20px;

    .page-title {
      margin: 0;
      font-size: 20px;
      font-weight: 600;
      color: #303133;
      display: flex;
      align-items: center;
      gap: 8px;

      i {
        color: #409EFF;
      }
    }

    .status-indicator {
      display: flex;
      align-items: center;
      gap: 8px;

      .status-dot {
        width: 8px;
        height: 8px;
        border-radius: 50%;

        &.online {
          background-color: #67C23A;
        }

        &.warning {
          background-color: #E6A23C;
        }

        &.offline {
          background-color: #F56C6C;
        }
      }

      .status-text {
        font-size: 14px;
        color: #606266;
      }
    }
  }

  .header-right {
    .el-button-group .el-button {
      border-radius: 4px;

      &:first-child {
        border-top-right-radius: 0;
        border-bottom-right-radius: 0;
      }

      &:last-child {
        border-top-left-radius: 0;
        border-bottom-left-radius: 0;
      }
    }
  }
}

// 响应式设计
@media (max-width: 768px) {
  .monitor-header {
    flex-direction: column;
    gap: 16px;

    .header-left,
    .header-right {
      width: 100%;
      justify-content: center;
    }
  }
}
</style>
